﻿using ITPaloozaPCL.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace ITPaloozaPCL.PCL.ViewModels
{
    public class PortableViewModel : INotifyPropertyChanged
    {
        #region Fields
        #endregion

        #region Properties
        /* Price List has no setter so that the collection ca not be replaced.
        * If the collection should be reset for any reason use PriceList.Clear() */
        private List<IStock> _PriceList = new List<IStock>();
        public List<IStock> PriceList
        {
            get
            {
                return _PriceList;
            }
        }
        #endregion

        #region Ctors
        public PortableViewModel()
        {

        }
        #endregion

        #region Public

        #region Change Collection
        /*Collection Change methods needed since there is no Observable Collection 
         * or System.Collections.ComponentModel in the lowest common denominator for windows phone 7 and Xbox360,
         * A list by nature will not notify any bound items of changes to its collection */
        public void AddStockPrices(IEnumerable<IStock> stocksToAdd)
        {
            PriceList.AddRange(stocksToAdd);
            OnPropertyChanged("PriceList");
        }

        public void AddStockPrice(IStock stockToAdd)
        {
            PriceList.Add(stockToAdd);
            OnPropertyChanged("PriceList");
        }

        public void RemoveStockPrices(IEnumerable<IStock> stocksToRemove)
        {
            foreach (var stock in stocksToRemove)
                PriceList.Remove(stock);

            OnPropertyChanged("PriceList");
        }

        public void RemoveStockPrice(IStock stockToRemove)
        {
            PriceList.Remove(stockToRemove);
            OnPropertyChanged("PriceList");
        }
        #endregion
        #endregion

        #region Private
        #endregion

        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
